package com.hevs.adibilis;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class OLDAddressActivity extends Activity implements OnClickListener {

	private TextView nameActiviyTextView, addressTextView, npaAndCityTextView, telefonTextView;
	private Button navigatoButton, callButton;
	private String longitude, latitude, name, telefon, locality, npa, address;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_address);

		// getting intent data
        Intent in = getIntent();
        
        // Get JSON values from previous intent
        name = in.getStringExtra("name"); //TODO lier au TAG_NAME de la classe precendente
        npa = in.getStringExtra("npa"); //TODO lier au TAG_NAME de la classe precendente
        locality = in.getStringExtra("locality"); //TODO lier au TAG_NAME de la classe precendente
        address = in.getStringExtra("address"); //TODO lier au TAG_NAME de la classe precendente
        telefon = in.getStringExtra("telephone"); //TODO lier au TAG_NAME de la classe precendente
        longitude = in.getStringExtra("longitude"); //TODO lier au TAG_NAME de la classe precendente
        latitude = in.getStringExtra("latitude"); //TODO lier au TAG_NAME de la classe precendente
        
        nameActiviyTextView = (TextView) findViewById(R.id.nameActivityTextView);
        nameActiviyTextView.setText(name);
        addressTextView = (TextView) findViewById(R.id.AddressTextView);
        addressTextView.setText(address);
        npaAndCityTextView = (TextView) findViewById(R.id.NPAAndCityTextView);
        npaAndCityTextView.setText(npa + " " + locality);
        telefonTextView = (TextView) findViewById(R.id.TelefonTextView);
        telefonTextView.setText(telefon);
        
      //  navigatoButton = (Button) findViewById(R.id.navigateToAddressButton);
        //navigatoButton.setOnClickListener(this);
		
        callButton = (Button) findViewById(R.id.callButton);
        callButton.setOnClickListener(this);
        
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.address, menu);
		return true;
	}

	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		
		if(arg0 == navigatoButton){
		//TODO redondance
		double latitude = Double.parseDouble(this.latitude);
		double longitude = Double.parseDouble(this.longitude);
		String label = name;
		String uriBegin = "geo:" + latitude + "," + longitude;
		String query = latitude + "," + longitude + "(" + label + ")";
		String encodedQuery = Uri.encode(query);
		String uriString = uriBegin + "?q=" + encodedQuery + "&z=2";
		Uri uri = Uri.parse(uriString);
		
		Intent intent = new Intent(Intent.ACTION_VIEW, uri);
		startActivity(intent);
		
		}
		else if(arg0 == callButton){
		
		  String url = "tel:"+telefon;
		  Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
		  startActivity(intent);
		}
		
	}
	


}
